package com.alibaba.cloud.cargo.application.command.impl;

import com.alibaba.cloud.cargo.application.command.IncidentLoggingCmdService;
import com.alibaba.cloud.cargo.application.command.cmd.HandlingEventAddCommand;
import com.alibaba.cloud.cargo.domain.aggregate.handlingevent.EventTypeEnum;
import com.alibaba.cloud.cargo.domain.aggregate.handlingevent.HandlingEvent;
import com.alibaba.cloud.cargo.domain.aggregate.handlingevent.HandlingEventRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class IncidentLoggingCmdServiceImpl implements IncidentLoggingCmdService {

    private final HandlingEventRepository handlingEventRepository;

    @Override
    public void addHandlingEvent(HandlingEventAddCommand cmd) {
        // validate

        // create 创建事件
        HandlingEvent handlingEvent = HandlingEvent.newHandlingEvent(cmd.getCargoId(),
                cmd.getDatetime(), EventTypeEnum.of(cmd.getEventType()), cmd.getScheduleId());

        // save 保存事件
        handlingEventRepository.save(handlingEvent);

        // 处理事件
        // 将事件发出，由对应的监听者进行处理

    }

}
